package com.zareal.controller;

import com.zareal.domain.PruductType;
import com.zareal.result.JSONResult;
import com.zareal.service.IPruductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/pruductType")
public class PruductTypeController {

    @Autowired
    public IPruductTypeService pruductTypeService;

    /**
    * 保存和修改公用的
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JSONResult saveOrUpdate(@RequestBody PruductType pruductType){
        if(pruductType.getId()!=null){
            pruductTypeService.updateById(pruductType);
        }else{
            pruductTypeService.insert(pruductType);
        }
        return JSONResult.success();
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JSONResult delete(@PathVariable("id") Long id){
        pruductTypeService.deleteById(id);
        return JSONResult.success();
    }

    /**
   * 获取对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(pruductTypeService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JSONResult list(){
        return JSONResult.success(pruductTypeService.selectList(null));
    }


}
